import re

def is_valid_currency_format(s):
    # 正则表达式匹配格式为数字后跟CNY或USD的字符串
    return re.match(r'^\d+(\.\d+)?\s*(CNY|USD)$', s) is not None

def convert_currency(amount, unit, usd_vs_rmb):
    if unit == 'CNY':
        return amount / usd_vs_rmb
    elif unit == 'USD':
        return amount * usd_vs_rmb
    else:
        raise ValueError("Unsupported currency unit")

def currency_converter_v4_0():
    usd_vs_rmb = 6.77  # 汇率，可以根据实际情况进行更新
    while True:
        currency_str_value = input('请输入带单位(CNY/USD)的货币金额：')
        if not is_valid_currency_format(currency_str_value):
            print("输入的货币格式不正确，请输入数字后跟CNY或USD。")
            continue

        # 分割金额和单位
        amount_str, unit = re.match(r'^\d+(\.\d+)?\s*(CNY|USD)$', currency_str_value).groups()
        try:
            amount = float(amount_str)
            converted_amount = convert_currency(amount, unit, usd_vs_rmb)
            print(f'转换后的{unit}金额是：{converted_amount:.2f}')
        except ValueError as e:
            print(e)

        continue_convert = input("是否继续进行货币转换？(y/n): ").strip().lower()
        if continue_convert != 'y':
            break

if __name__ == "__main__":
    currency_converter_v4_0()